package io.alvin.jframework.plugin.security;

import org.apache.shiro.web.env.EnvironmentLoaderListener;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;
import java.util.Set;

/**
 * Created by Alvin on 2017/7/15.
 */
public class SecurityPlugin implements ServletContainerInitializer {

    public void onStartup(Set<Class<?>> handleTypes, ServletContext servletContext) throws ServletException {
        // 设置初始化参数
        servletContext.setInitParameter("shiroConfigLocation", "classpath:security.ini");
        // 注册Listener
        servletContext.addListener(EnvironmentLoaderListener.class);
        // 注册Fileter
        FilterRegistration.Dynamic securityFilter = servletContext.addFilter("securityFilter", SecurityFilter.class);
        securityFilter.addMappingForUrlPatterns(null, false, "/*");
    }
}
